package com.esoon.controller;

import com.esoon.service.CsrCallLostService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * @ClassName CsrCallLostController
 * @Description TODO  呼损列表
 * @Author 2020/11/13 10:13
 * @Version 1.0
 **/
@RestController
@RequestMapping("/v1/callLost")
public class CsrCallLostController {

    private static final Logger logger;

    static {
        logger = LoggerFactory.getLogger(CsrCallLostController.class);
    }
    @Resource
    private CsrCallLostService csrCallLostService;
    @RequestMapping(value = "/insert" ,method = RequestMethod.GET)
    public int insertCallLost(@RequestParam String clPhone,@RequestParam String clSkill,@RequestParam String tenantCode){

        logger.info("invoking callLost interface , the url = '/v1/callLost/insert', the requestParam :  clPhone = [{}] , clSkill = [{}] , tenantCode = [{}]" , clPhone , clSkill , tenantCode );
      return  csrCallLostService.insert(clPhone,clSkill,tenantCode);
    }
/*
 * @Author Jack
 * @Description //TODO 业务逻辑： 根据电话号码查询呼损表，
 * @Date 16:08 2020/11/13
 * @Param
 * @return
 **/
    @RequestMapping(value = "/selectAbandonPhone",method = RequestMethod.GET)
    public String selectAbandonPhone(@RequestParam String phone,@RequestParam String tenantCode){
        try {
            //在程序进入到这里的时候创建一个时间对象，根据该时间点获取之前三十分钟的时间点。
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
            simpleDateFormat.applyPattern("yyyy-MM-dd HH:mm:ss");
            Calendar instance = Calendar.getInstance();
            String endTime = simpleDateFormat.format(instance.getTime());
            instance.add(Calendar.MINUTE, -30);
            String startTime = simpleDateFormat.format(instance.getTime());
            logger.info("invoking 30 minute twice callLost interface , the url = '/v1/callLost/selectAbandonPhone' the requestParam:  phone = [{}] , tenantCode = [{}] , endTime = [{}] , startTime = [{}]" , phone , tenantCode , endTime , startTime);
            return csrCallLostService.selectAbandonPhone(startTime, endTime, phone, tenantCode);
        }catch (Exception e){
            return "500";
        }
    }
}
